package catalogo.dao;

import java.util.List;



import org.hibernate.Query;
import org.hibernate.Session;
//import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;


import catalogo.entidades.TipoReceta;

@Repository
public class TipoRecetaDAOImpl implements TipoRecetaDAO 
{
	
	private SessionFactory sessionFactory;

	public SessionFactory getSessionFactory()
	{
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@SuppressWarnings("unchecked")
	public List<TipoReceta> obtenerTodosLosTiposRecetas()
	{
		List<TipoReceta> list = getSessionFactory().getCurrentSession().createQuery("from TipoReceta").list();
		return  list;
	}
	

	@Autowired
	public TipoReceta obtenerTipoRecetaPorId(String idTipo)
	{
		Session session = sessionFactory.getCurrentSession();
		//session.beginTransaction();
		Query query =session.createQuery("from TipoReceta where idTipo = ?");
		query.setParameter(0, idTipo);
		TipoReceta resultado = (TipoReceta) query.uniqueResult();
		return resultado;
		
		/*List list = getSessionFactory().getCurrentSession().createQuery("from TipoReceta where idTipo=?").setParameter(0, idTipo).list();
        return (TipoReceta)list.get(0);*/
	}
	


}
